<?php
/*
 * tiers/load-index.phtml
 */
?>

<div class='content-body'>
    <div class='list-container'>
	<table class="table table-striped list-table">
	    <thead>
		<tr>
		    <td width='29%'>Libellé</td>
		    <td width='29%'>Contact</td>
                  <td width='29%'>Adresse</td>
		    <td width='13%'>&nbsp;</td>
		</tr>
	    </thead>
	    <tbody>
                <?php if (count($list_tiers) ): ?>
                    <?php foreach ($list_tiers as $tiers): ?>
                            <tr>
                                <td style="text-align: center;">

                                    <?php echo $tiers->libelle; ?>
                                </td>
                                <td>
                                    <?php echo $tiers->contact; ?>    			
                                </td>
                                <td>
                                    <?php echo $tiers->adresse; ?>    			
                                </td>

                                <td style='text-align: center;'>       
                                    &nbsp;&nbsp;&nbsp;                        
                                    <a href='<?php echo $this->url('RHX/default', array('controller'	 => 'tiers', 'action'	 => 'edit', 'id' => $tiers->id )) ?>' id='edit-<?php echo $tiers->id; ?>' class="edit-tiers" data-tiers="<?php echo $tiers->id; ?>" ><img src='<?php echo $this->basePath() . '/img/rhx/edit-16x15.png' ?>' alt='Editer' title='Editer'></a>
                                    &nbsp;&nbsp;&nbsp; 
                                    <a href='#' id='delete-<?php echo $tiers->id; ?>' class="delete-tiers" data-tiers="<?php echo $tiers->id; ?>" data-libelle="<?php echo $tiers->libelle; ?>">
                                        <img src='<?php echo $this->basePath() . '/img/rhx/delete-16x16.png' ?>' alt='Effacer' title='Effacer'>
                                    </a>		
                                </td>
                            </tr>
                        <?php endforeach; ?>
                <?php else : ?>
                      <tr>
                            <td colspan="4">Aucun Tiers</td>                            
                        </tr>
                <?php endif; ?>
	    </tbody>
	</table>
    </div>
</div>

<script type="text/javascript">
    // Démarrage
    $(function(){
	
	$('.delete-tiers').click(function(e){
           var $this = $(this);
	    e.preventDefault();
	    libelle = $this.data('libelle');
	    conf = confirm("Voulez-vous effacer le tiers \"" + libelle + "\" ?");
	    if(!conf){
		return false;
	    }
	    tiers_id = $this.data('tiers');
	    ajax = $.ajax({
		type: 'post',
		url : '<?php echo $this->url('RHX/default', array('controller'	 => 'tiers', 'action'	 => 'delete')) ?>',
		data: '&id='+ tiers_id
	    });
	    ajax.done(function(result){
                window.location.reload();
	    });
	    
	});
    });

</script>